package com.c.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.c.entity.*;
import com.c.mapper.AddressMapper;
import com.c.mapper.OrderFormMapper;
import com.c.mapper.OrderMapper;
import com.c.service.MemberService;
import com.c.service.OrderFormService;
import com.c.service.SetmealService;
import com.c.service.UserService;
import com.c.utils.OrderNoUtil;
import com.c.utils.PageResult;
import com.c.utils.QueryPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * @author wangxiangli
 * @create 2022-12-25-12:30
 */
@Service
@Transactional
public class OrderFormServiceImpl extends ServiceImpl<OrderFormMapper, OrderForm> implements OrderFormService {

    @Autowired
    private UserService userService;
    @Autowired
    private SetmealService setmealService;
    @Autowired
    private MemberService memberService;
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private AddressMapper addressMapper;


    @Override
    public PageResult pageQuery2(QueryPageBean queryPageBean) {
        //统计所有的数据
        Long total = baseMapper.selectCount(null);
        if(total>=queryPageBean.getPageSize()*(queryPageBean.getCurrentPage()-1)){
            Integer[] orderFormids=baseMapper.selectIdsByCondtion(queryPageBean.getQueryString(),queryPageBean.getPageSize()*(queryPageBean.getCurrentPage()-1),queryPageBean.getPageSize());
            if(orderFormids==null){
                return null;
            }
            List<OrderForm> orderForms=baseMapper.selectOrderForms(orderFormids);
            return new PageResult(total,orderForms);
        }
        return null;
    }



    @Override
    public OrderForm getOrderInfoById(String orderId) {
        QueryWrapper<OrderForm> wrapper = new QueryWrapper<>();
        wrapper.eq("order_no",orderId);
        OrderForm orderForm = baseMapper.selectOne(wrapper);
        return orderForm;
    }


}
